package com.mall.service.impl;

import com.mall.common.utils.Security;
import com.mall.dao.custom.CtAddressMapper;
import com.mall.entity.Address;
import com.mall.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author xyl
 * @date 2021-03-03 15:23
 */
@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    private CtAddressMapper addressMapper;

    @Override
    public int add(Address address) {
        address.setCreateBy(Security.getCurrentUserId());
        address.setCreateTime(new Date());
        return addressMapper.insert(address);
    }

    @Override
    public int modify(Address address) {
        address.setUpdateBy(Security.getCurrentUserId());
        address.setUpdateTime(new Date());
        return addressMapper.updateByPrimaryKeySelective(address);
    }

    @Override
    public int remove(Integer addressId) {
        return addressMapper.deleteByPrimaryKey(addressId);
    }

    @Override
    public List<Address> list(Address address) {
        address.setCreateBy(Security.getCurrentUserId());
        return addressMapper.selectAll(address);
    }

    @Override
    public Address get(Integer addressId) {
        return addressMapper.selectByPrimaryKey(addressId);
    }
}
